var o, e = require,
    t = module,
    n = exports,
    i = this && this.__extends || (o = function(t, e) {
        return (o = Object.setPrototypeOf || {
                __proto__: []
            }
            instanceof Array && function(t, e) {
                t.__proto__ = e;
            } || function(t, e) {
                for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
            })(t, e);
    }, function(t, e) {
        function i() {
            this.constructor = t;
        }
        o(t, e), t.prototype = null === e ? Object.create(e) : (i.prototype = e.prototype,
            new i());
    }),
    a = this && this.__decorate || function(t, e, i, o) {
        var n, a = arguments.length,
            r = a < 3 ? e : null === o ? o = Object.getOwnPropertyDescriptor(e, i) : o;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, i, o);
        else
            for (var s = t.length - 1; 0 <= s; s--)(n = t[s]) && (r = (a < 3 ? n(r) : 3 < a ? n(e, i, r) : n(e, i)) || r);
        return 3 < a && r && Object.defineProperty(e, i, r), r;
    };

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("EditView"),
    s = e("GameBlock"),
    c = e("GameManager"),
    l = e("LoseView"),
    d = e("PrefabView"),
    u = e("GameRank"),
    p = e("GameMap"),
    h = e("TipsView"),
    f = e("AStar"),
    g = e("TimeView"),
    m = e("KillView"),
    y = e("Player"),
    v = e("PlayerMain"),
    w = e("PlayerAI"),
    b = e("GameAttack"),
    P = e("Global"),
    I = e("VisitView"),
    G = e("LoadManager"),
    _ = e("CriView"),
    A = e("PlayerModel"),
    k = e("AudioManager"),
    M = e("GameConfig"),
    C = e("GameData"),
    D = e("GameSkeleton"),
    S = e("GameSprite"),
    O = cc._decorator,
    R = O.ccclass,
    T = O.property,
    x = function(e) {
        function t() {
            var t = null !== e && e.apply(this, arguments) || this;
            return t.map = null, t.layout = null, t.bulletLayout = null, t.bulletSpriteLayout = null,
                t.bulletSkeletonLayout = null, t.criLayout = null, t.bottom = null, t.top = null,
                t.tex = null, t.shadow = null, t.tipsView = null, t.loseView = null, t.visitView = null,
                t.attackView = null, t.rankView = null, t.mapView = null, t.timeView = null, t.killView = null,
                t.gameEggs = null, t.block = null, t.blocks = [], t.item = null, t.itemPool = new cc.NodePool(),
                t.arm = null, t.armPool = new cc.NodePool(), t.fire = null, t.firePool = new cc.NodePool(),
                t.cri = null, t.criPool = new cc.NodePool(), t.skeleton = null, t.skeletonPool = new cc.NodePool(),
                t.sprite = null, t.spritePool = new cc.NodePool(), t.aiPrefab = null, t.petPrefab = null,
                t.prefabMap = new Map(), t.astar = null, t.curPlayer = null, t.followPlayer = null,
                t.players = [], t.ais = [], t.targets = [], t.items = [], t.points = [], t.enemy_point = [],
                t.size = cc.Vec2.ZERO, t.followCamera = null, t.roleCamera = null, t.isAccount = !1,
                t;
        }
        return i(t, e), t.prototype.onEnable = function() {
                c.default.getInstance().playTypeList.includes(c.PlayType.圣诞) && k.default.getInstance().playBg("圣诞BGM");
            }, t.prototype.onDisable = function() {
                c.default.getInstance().playTypeList.includes(c.PlayType.圣诞) && k.default.getInstance().playBg("背景"),
                    e.prototype.onDisable.call(this);
            }, t.prototype.onLoad = function() {}, t.prototype.start = function() {}, t.prototype.load = function(e) {
                var i = this;
                G.default.getInstance().loadSpriteFrame({
                    url: c.default.getInstance().bgPath,
                    sprite: this.map.getComponent(cc.Sprite)
                }), G.default.getInstance().loadRes({
                    url: c.default.getInstance().jsonPath,
                    type: cc.JsonAsset
                }).then(function(t) {
                    i.init(t.json), e && e();
                });
            }, t.prototype.init = function(t) {
                var n, a, c = this;
                t.size && (this.size = cc.v2(t.size.width, t.size.height), this.map.setContentSize(cc.size(80 * t.size.width, 80 * t.size.height))),
                    t.point && (this.points = t.point.map(function(t) {
                        return cc.v2(t);
                    }).sort(function() {
                        return Math.random() - .5;
                    })), t.enemy_point && (this.enemy_point = t.enemy_point.map(function(t) {
                        return cc.v2(t);
                    }).sort(function() {
                        return Math.random() - .5;
                    })), t.dress_block && t.dress_block.forEach(function(t) {
                        var e = cc.instantiate(c.block),
                            i = e.getComponent(s.default);
                        i && (i.gird = cc.v2(t.x, t.y), i.type = r.BlockType.BLOCK, e.setParent(c.layout),
                            e.setPosition(cc.v2(80 * i.gird.x + 40 - c.map.width / 2, 80 * i.gird.y + 40 - c.map.height / 2)),
                            c.blocks.push(i));
                    }), t.boxs && (n = [], a = [], t.boxs.map(function(t) {
                        var e = "";
                        switch (t.t) {
                            case r.BlockType.DEFAULT:
                                e = "texture/map/default/" + t.n;
                                break;

                            case r.BlockType.BLOCK:
                                e = "texture/map/block/" + t.n;
                                break;

                            case r.BlockType.BOX:
                                e = "texture/map/box/" + t.n;
                                break;

                            case r.BlockType.GRASS:
                                e = "texture/map/grass/" + t.n;
                                break;

                            case r.BlockType.WATER:
                                e = "texture/map/water/" + t.n;
                                break;

                            case r.BlockType.DRESS:
                                e = "texture/map/dress/" + t.n;
                                break;

                            case r.BlockType.DRESS_BIG:
                                e = "texture/map/dressBig/" + t.n;
                        }
                        var i = cc.instantiate(c.block),
                            o = i.getComponent(s.default);
                        o && (o.name = t.n, o.url = e, o.gird = cc.v2(t.g), o.type = t.t, n.includes(e) || n.push(e),
                            i.setParent(c.layout), i.setPosition(cc.v2(80 * o.gird.x + 40 - c.map.width / 2, 80 * o.gird.y + 40 - c.map.height / 2)),
                            o.type == r.BlockType.WATER ? i.zIndex = 2 * -o.gird.y - 4 * c.map.height : o.type == r.BlockType.GRASS ? (a.includes("prefab/animation/" + o.name) || a.push("prefab/animation/" + o.name),
                                i.zIndex = 2 * -o.gird.y) : o.type == r.BlockType.DRESS ? i.zIndex = 2 * -o.gird.y - 2 * c.map.height : (o.type,
                                r.BlockType.DRESS_BIG, i.zIndex = 2 * -o.gird.y), c.blocks.push(o));
                    }), Promise.all(n.map(function(e) {
                        return new Promise(function(t) {
                            G.default.getInstance().loadRes({
                                url: e,
                                type: cc.SpriteFrame
                            }).then(function() {
                                t();
                            }).catch(function() {
                                t();
                            });
                        });
                    }).concat(a.map(function(i) {
                        return new Promise(function(e) {
                            G.default.getInstance().loadRes({
                                url: i,
                                type: cc.Prefab
                            }).then(function(t) {
                                c.prefabMap.set(i, t), e();
                            }).catch(function() {
                                e();
                            });
                        });
                    }))).then(function() {
                        c.blocks.forEach(function(t) {
                            return t.url && t.init(t.url);
                        });
                    })), this.astar || (this.astar = new f.default()), this.astar.init(80, 80, Math.floor(this.map.width / 80) - 1, Math.floor(this.map.height / 80) - 1),
                    this.astar.initMap(), this.astar.resetMap(), this.blocks.forEach(function(t) {
                        t.type != r.BlockType.BLOCK && t.type != r.BlockType.BOX && t.type != r.BlockType.WATER || 0 != c.astar.gridsList[t.gird.x][t.gird.y].type ? t.type == r.BlockType.GRASS && (c.astar.gridsList[t.gird.x][t.gird.y].target = t) : (c.astar.gridsList[t.gird.x][t.gird.y].type = -1,
                            c.astar.gridsList[t.gird.x][t.gird.y].target = t);
                    }), this.initPlayer();
            }, t.prototype.initPlayer = function() {
                var i = this;
                c.default.getInstance().model.ais.forEach(function(t) {
                        var e = cc.instantiate(i.aiPrefab);
                        e.parent = i.layout;
                        e = e.getComponent(w.default);
                        e.initData(t), i.ais.push(e);
                    }), this.targets = this.layout.getComponentsInChildren(y.default), this.players = this.layout.getComponentsInChildren(v.default),
                    this.curPlayer = this.players[0], this.followPlayer = this.curPlayer, this.curPlayer.initData(c.default.getInstance().model.curPlayer),
                    c.default.getInstance().model.players = this.players.map(function(t) {
                        return t.model;
                    }), this.players.forEach(function(t) {
                        return t.init();
                    }), this.curPlayer.node.active = !0;
            }, t.prototype.doStart = function() {
                this.node.active = !0, this.tipsView ? ((this.tipsView.gamView = this).tipsView.node.active = !0,
                    this.tipsView.startGame()) : c.default.getInstance().startGame();
            }, t.prototype.doEnd = function() {
                this.ais && this.ais.forEach(function(t) {
                    return t.isStart = !1;
                });
            }, t.prototype.doAir = function() {
                var t = this;
                20 < this.timeView.num && !this.isAccount && (c.default.getInstance().playTypeList.includes(c.PlayType.道具) ? this.scheduleOnce(function() {
                    t.doAir(), cc.systemEvent.emit("game_air");
                }, GA.rand(M.GC.gameAirItemMinTime, M.GC.gameAirItemMaxTime)) : this.scheduleOnce(function() {
                    t.doAir(), cc.systemEvent.emit("game_air");
                }, GA.rand(M.GC.gameAirMinTime, M.GC.gameAirMaxTime)));
            }, t.prototype.doChristmas = function() {
                var e = this;
                G.default.getInstance().loadRes({
                    url: "prefab/gameChristmas",
                    type: cc.Prefab
                }).then(function(t) {
                    t = cc.instantiate(t);
                    t.parent = e.top, t.zIndex = 1e3;
                });
            }, t.prototype.startGame = function() {
                var t = this;
                this.attackView.node.active = !0, this.timeView && (this.timeView.node.active = !0,
                        c.default.getInstance().playTypeList.includes(c.PlayType.元旦) ? this.timeView.init(M.GC.gameChristmasTime) : c.default.getInstance().playTypeList.includes(c.PlayType.圣诞) ? (this.timeView.init(M.GC.gameChristmasTime),
                            this.doChristmas()) : c.default.getInstance().matchType == c.MatchType.三对三 ? this.timeView.init(M.GC.gameBattleTime) : this.timeView.init(M.GC.gameTime),
                        this.timeView.startTimer(), this.timeView.node.on("finished", function() {
                            t.doEnd(), c.default.getInstance().endGame();
                        }, this), !M.GC.isVaild("item") && P.G.getRank(C.GD.level).r >= M.GC.gameAirRank && this.doAir()),
                    this.rankView && (M.GC.isVaild("gameRank") || (this.rankView.node.active = !0, this.rankView.init(this.players))),
                    this.mapView && (this.mapView.node.active = !0, this.mapView.init(Math.max(this.map.width, this.map.height))),
                    this.shadow.active = !1, this.players.forEach(function(t) {
                        return t.isStart = !0;
                    }), this.layout.getComponentsInChildren("PlayerPet").forEach(function(t) {
                        return t.isStart = !0;
                    });
            }, t.prototype.loseGame = function() {
                this.shadow.active = !0, this.loseView && (this.loseView.node.active = !0);
            }, t.prototype.endGame = function() {
                this.isAccount || (this.isAccount = !0, this.loseView && (this.loseView.node.active = !1),
                    this.visitView && (this.visitView.node.active = !1), this.timeView && this.timeView.pauseTimer(),
                    this.attackView.isAttack = !1, this.shadow.active = !0, this.tipsView ? (this.tipsView.node.active = !0,
                        this.tipsView.endGame()) : c.default.getInstance().accountGame());
            }, t.prototype.visitGame = function() {
                this.shadow.active = !0, this.visitView && (this.visitView.node.active = !0);
            }, t.prototype.accountGame = function() {
                this.shadow.active = !1;
            }, t.prototype.showKill = function(t, e) {
                this.killView && (this.killView.init(t, e), this.killView.node.active = !0), this.unschedule(this.hideKill),
                    this.scheduleOnce(this.hideKill, 2);
            }, t.prototype.hideKill = function() {
                this.unschedule(this.hideKill), this.killView && (this.killView.node.active = !1);
            }, t.prototype.checkEmptyGird = function(a, r, s, c) {
                var e = this;
                void 0 === a && (a = 0), void 0 === r && (r = 0), s = s || this.size.x, c = c || this.size.y;
                for (var t = this.size.x, p = this.size.y, l = [], u = (u = this.blocks.map(function(t) {
                        return t.gird;
                    })).concat(this.players.map(function(t) {
                        t = cc.v2(t.node.x + (e.map.width - 80) / 2, t.node.y + (e.map.height - 80) / 2);
                        return cc.v2(Math.floor(t.x / 80), Math.floor(t.y / 80));
                    })).concat(this.items.filter(function(t) {
                        return t.node;
                    }).map(function(t) {
                        t = cc.v2(t.node.x + (e.map.width - 80) / 2, t.node.y + (e.map.height - 80) / 2);
                        return cc.v2(Math.floor(t.x / 80), Math.floor(t.y / 80));
                    })), i = [], o = 0; o < t; o++) ! function(e) {
                    var t = [],
                        i = u.filter(function(t) {
                            return t.x == e;
                        });
                    if (a < e && e < s)
                        if (0 < i.length)
                            for (var o = Math.max(r, 0); o < Math.min(c, p); o++) ! function(e) {
                                i.every(function(t) {
                                    return t.y != e;
                                }) && t.push(e);
                            }(o);
                        else
                            for (var n = Math.max(r, 0); n < Math.min(c, p); n++) t.push(n);
                    l.push(t);
                }(o);
                if (l.forEach(function(t, e) {
                        0 < t.length && i.push(e);
                    }), 0 == i.length) return null;
                var n = i[Math.floor(Math.random() * i.length)];
                if (0 == l.length || !l[n] || 0 == l[n].length) return null;
                var h = l[n][Math.floor(Math.random() * l[n].length)];
                return cc.v2(n, h);
            }, t.prototype.getEmptyGird = function() {
                return 0 < this.points.length ? this.points.pop() : this.checkEmptyGird();
            }, t.prototype.getEnemyEmptyGird = function() {
                return 0 < this.enemy_point.length ? this.enemy_point.pop() : this.checkEmptyGird();
            }, t.prototype.getRes = function(t, e) {
                e = 0 < t.size() ? t.get() : cc.instantiate(e);
                return e.active = !0, e;
            }, t.prototype.putRes = function(t, e) {
                t ? t.put(e) : e && e.destroy();
            }, t.prototype.getItem = function() {
                return this.getRes(this.itemPool, this.item);
            }, t.prototype.putItem = function(t) {
                this.putRes(this.itemPool, t);
            }, t.prototype.getArm = function() {
                return this.getRes(this.armPool, this.arm);
            }, t.prototype.putArm = function(t) {
                this.putRes(this.armPool, t);
            }, t.prototype.getFire = function() {
                return this.getRes(this.firePool, this.fire);
            }, t.prototype.putFire = function(t) {
                this.putRes(this.firePool, t);
            }, t.prototype.getCri = function() {
                return this.getRes(this.criPool, this.cri);
            }, t.prototype.putCri = function(t) {
                this.putRes(this.criPool, t);
            }, t.prototype.appendCri = function(t, e, i, o) {
                var n = this,
                    a = this.getCri().getComponent(_.default);
                a && (a.node.parent = this.criLayout, a.node.setPosition(e.add(cc.v2(50 * Math.random() - 50, 20 * Math.random() + 100))),
                    a.node.scale = 0, o ? (C.GD.isVibrate && (null === (o = null === (e = GA.PA) || void 0 === e ? void 0 : e.vibrateShort) || void 0 === o || o.call(e, {})),
                        a.init(2 * i, t == A.ArmType.彩蛋枪 ? 2 : 1), cc.tween(a.node).then(cc.sequence(cc.scaleTo(.1, t == A.ArmType.彩蛋枪 ? 12 : 8), cc.delayTime(.2), cc.scaleTo(.1, 0)).easing(cc.easeOut(3))).call(function() {
                            n.putCri(a.node);
                        }).start()) : (a.init(i, t == A.ArmType.彩蛋枪 ? 2 : 0), cc.tween(a.node).then(cc.sequence(cc.scaleTo(.08, t == A.ArmType.彩蛋枪 ? 4 : 3), cc.delayTime(.2), cc.scaleTo(.08, 0)).easing(cc.easeOut(3))).call(function() {
                        n.putCri(a.node);
                    }).start()));
            }, t.prototype.getPet = function() {
                return cc.instantiate(this.petPrefab);
            }, t.prototype.getSkeleton = function() {
                return this.getRes(this.skeletonPool, this.skeleton);
            }, t.prototype.putSkeleton = function(t) {
                this.putRes(this.skeletonPool, t);
            }, t.prototype.appendSkeleton = function(n) {
                var a = this;
                return new Promise(function(e, t) {
                    var i, o = a.getSkeleton();
                    o ? (null == (i = o.getComponent(D.default)) && ((i = o.addComponent(D.default)).skeleton = o.getComponent(sp.Skeleton)),
                        i.init(n).then(function(t) {
                            e(t);
                        }).catch(function() {
                            a.removeSkeleton(o), t();
                        })) : t();
                });
            }, t.prototype.removeSkeleton = function(t) {
                var e;
                t && (null == (e = t.getComponent(D.default)) && ((e = t.addComponent(D.default)).skeleton = t.getComponent(sp.Skeleton)),
                    e.reset(), this.putSkeleton(t));
            }, t.prototype.getSprite = function() {
                return this.getRes(this.spritePool, this.sprite);
            }, t.prototype.putSprite = function(t) {
                this.putRes(this.spritePool, t);
            }, t.prototype.appendSprite = function(n) {
                var a = this;
                return new Promise(function(e, t) {
                    var i, o = a.getSprite();
                    o ? (null == (i = o.getComponent(S.default)) && ((i = o.addComponent(S.default)).sprite = o.getComponent(cc.Sprite)),
                        i.init(n).then(function(t) {
                            e(t);
                        }).catch(function() {
                            a.removeSprite(o), t();
                        })) : t();
                });
            }, t.prototype.removeSprite = function(t) {
                var e;
                t && (null == (e = t.getComponent(S.default)) && ((e = t.addComponent(S.default)).sprite = t.getComponent(cc.Sprite)),
                    e.reset(), this.putSprite(t));
            }, t.prototype.appendParticle = function(t, i, o, n) {
                var a = this,
                    r = new cc.Node().addComponent(cc.ParticleSystem);
                r && cc.resources.load(t, cc.ParticleAsset, function(t, e) {
                    !t && e instanceof cc.ParticleAsset ? (r.file = e, G.default.getInstance().loadRes({
                        url: i,
                        type: cc.SpriteFrame
                    }).then(function(t) {
                        t instanceof cc.SpriteFrame ? (r.spriteFrame = t, o && o(r)) : a.removeParticle(r, n);
                    }).catch(function() {
                        a.removeParticle(r, n);
                    })) : a.removeParticle(r, n);
                });
            }, t.prototype.removeParticle = function(t, e) {
                t && t.node && t.node.destroy(), e && e();
            }, t.prototype.getPrefab = function(i) {
                var o = this;
                return new Promise(function(e) {
                    o.prefabMap.has(i) ? e(o.prefabMap.get(i)) : G.default.getInstance().loadRes({
                        url: i,
                        type: cc.Prefab
                    }).then(function(t) {
                        o.prefabMap.set(i, t), e(t);
                    }).catch(function() {
                        e(null);
                    });
                });
            }, t.prototype.checkVisual = function(t) {
                for (var e = this.astar.getGird(t), i = c.default.getInstance().fieldgird, o = -i; o <= i; o++)
                    for (var n = Math.abs(o), a = -i + n; a <= i - n; a++) {
                        var p = e.x + o,
                            l = e.y + a;
                        0 <= p && p <= this.astar.mapW && 0 <= l && l <= this.astar.mapH && (!(l = this.astar.gridsList[p][l]) || (l = l.target) instanceof s.default && l.type == r.BlockType.GRASS && (l.isUpdate = !0));
                    }
            }, t.prototype.refreshMap = function() {
                var t = Math.abs((cc.winSize.width - this.map.width * this.map.scale * this.followCamera.zoomRatio) / 2),
                    e = Math.abs((cc.winSize.height - this.map.height * this.map.scale * this.followCamera.zoomRatio) / 2);
                this.map.x > t ? this.map.x = t : this.map.x < -t && (this.map.x = -t), this.map.y > e ? this.map.y = e : this.map.y < -e && (this.map.y = -e);
            }, t.prototype.updateRank = function(t, e) {
                this.rankView && this.rankView.refresh(t, e);
            }, t.prototype.updateMap = function(t) {
                this.mapView && this.mapView.refresh(t);
            }, t.prototype.pause = function() {
                this.loseView && (this.loseView.isPause = !0), this.ais && this.ais.forEach(function(t) {
                    return t.isStart = !1;
                }), this.timeView && this.timeView.pauseTimer();
            }, t.prototype.resume = function() {
                this.loseView && (this.loseView.isPause = !1), this.ais && this.ais.forEach(function(t) {
                    return t.isStart = !0;
                }), this.timeView && this.timeView.resumeTimer();
            }, t.prototype.update = function(e) {
                this.updateMap(this.players), this.blocks.forEach(function(t) {
                    return t.isUpdate && t.doUpdate(e);
                });
            }, a([T(cc.Node)], t.prototype, "map", void 0), a([T(cc.Node)], t.prototype, "layout", void 0),
            a([T(cc.Node)], t.prototype, "bulletLayout", void 0), a([T(cc.Node)], t.prototype, "bulletSpriteLayout", void 0),
            a([T(cc.Node)], t.prototype, "bulletSkeletonLayout", void 0), a([T(cc.Node)], t.prototype, "criLayout", void 0),
            a([T(cc.Node)], t.prototype, "bottom", void 0), a([T(cc.Node)], t.prototype, "top", void 0),
            a([T(cc.Node)], t.prototype, "tex", void 0), a([T(cc.Node)], t.prototype, "shadow", void 0),
            a([T(h.default)], t.prototype, "tipsView", void 0), a([T(l.default)], t.prototype, "loseView", void 0),
            a([T(I.default)], t.prototype, "visitView", void 0), a([T(b.default)], t.prototype, "attackView", void 0),
            a([T(u.default)], t.prototype, "rankView", void 0), a([T(p.default)], t.prototype, "mapView", void 0),
            a([T(g.default)], t.prototype, "timeView", void 0), a([T(m.default)], t.prototype, "killView", void 0),
            a([T(cc.Node)], t.prototype, "block", void 0), a([T(cc.Node)], t.prototype, "item", void 0),
            a([T(cc.Node)], t.prototype, "arm", void 0), a([T(cc.Node)], t.prototype, "fire", void 0),
            a([T(cc.Node)], t.prototype, "cri", void 0), a([T(cc.Node)], t.prototype, "skeleton", void 0),
            a([T(cc.Node)], t.prototype, "sprite", void 0), a([T(cc.Prefab)], t.prototype, "aiPrefab", void 0),
            a([T(cc.Prefab)], t.prototype, "petPrefab", void 0), a([T(cc.Camera)], t.prototype, "followCamera", void 0),
            a([T(cc.Camera)], t.prototype, "roleCamera", void 0), a([R], t);
    }(d.default);

n.default = x;